﻿using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        tbOutput.Text = "#" + RijndaelSimple.Encrypt(
            tbInput.Text,
                tbPassphrase.Text,
                "fobar",
                "SHA1",
                2,
                "@1B2c3D4e5F6g7H8",
                256);
    }
    protected void DecodeBtn_Click(object sender, EventArgs e)
    {
        string crypt = tbOutput.Text;

        //parse
        //Text = crypt;
        if (crypt.IndexOf('#') > 0)
            crypt = crypt.Substring(crypt.IndexOf('#') + 1);
        else if (crypt.StartsWith("#"))
            crypt = crypt.Substring(1);
        else
        {
            lbError.Text = "No crypto found.\n" + crypt;
            return;
        }

        //decode
        try
        {
            tbInput.Text = RijndaelSimple.Decrypt(
                crypt,
                tbPassphrase.Text,
                "fobar",
                "SHA1",
                2,
                "@1B2c3D4e5F6g7H8",
                256);
        }
        catch (FormatException ex)
        {
            lbError.Text = ("error decoding\nError: " + ex.Message + "\n\nHash: " + crypt);
        }
        catch (Exception ex)
        {
            lbError.Text = ("nope:\n" + ex.Message + ex.StackTrace);
        }
    }
}
